package view;

import java.awt.SystemColor;
import java.util.ArrayList;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * @uthor BWH
 */

public class GUI_Admin extends JPanel {
	TeraFootMain teraFootMain;
	private final JTextField textBruger;
	private final JTextField textKode;
	JButton btnOpret;
	JLabel lblStatus;
	private final JLabel lblForAtndre;
	JComboBox comboBox;
	JButton btnSletBruger;

//	private JTextField textURL;
//	private JTextField textRoot;
//	JButton btnOpdaterInfo;
//	JButton btnOpretDB;

	/**
	 * @param args
	 */

	public GUI_Admin(TeraFootMain teraFootMain) {
		setBackground(SystemColor.activeCaption);
		this.teraFootMain = teraFootMain;
		setLayout(null);

		final JLabel lblOpretNytLog = new JLabel("Opret nyt login");
		lblOpretNytLog.setBounds(10, 11, 147, 14);
		add(lblOpretNytLog);

		final JLabel lblBrugernavn = new JLabel("Brugernavn:");
		lblBrugernavn.setBounds(10, 36, 101, 14);
		add(lblBrugernavn);

		final JLabel lblKodeord = new JLabel("Password:");
		lblKodeord.setBounds(10, 61, 101, 14);
		add(lblKodeord);

		textBruger = new JTextField();
		textBruger.setActionCommand("Opret bruger");
		textBruger.addActionListener(teraFootMain.getAcListener());
		textBruger.setBounds(110, 33, 147, 20);
		add(textBruger);
		textBruger.setColumns(10);

		textKode = new JTextField();
		textKode.setActionCommand("Opret bruger");
		textKode.addActionListener(teraFootMain.getAcListener());
		textKode.setBounds(110, 58, 147, 20);
		add(textKode);
		textKode.setColumns(10);

		btnOpret = new JButton("Opret");
		btnOpret.setBounds(267, 57, 89, 23);
		btnOpret.setActionCommand("Opret bruger");
		btnOpret.addActionListener(teraFootMain.getAcListener());
		add(btnOpret);

		lblStatus = new JLabel("");
		lblStatus.setBounds(259, 93, 354, 19);
		lblStatus.setBackground(SystemColor.activeCaption);
		lblStatus.setOpaque(true);
		add(lblStatus);

		lblForAtndre = new JLabel(
				"For at \u00E6ndre koden: Skriv brugernavn og \u00F8nskede password i felterne og svar ja efterf\u00F8lgende.");
		lblForAtndre.setBounds(10, 114, 590, 30);
		add(lblForAtndre);

		comboBox = new JComboBox();
		refreshComboBox();
		comboBox.setBounds(139, 89, 118, 20);
		add(comboBox);

		btnSletBruger = new JButton("Slet bruger");
		btnSletBruger.setActionCommand("Slet bruger");
		btnSletBruger.addActionListener(teraFootMain.getAcListener());
		btnSletBruger.setBounds(10, 89, 125, 23);
		add(btnSletBruger);

//		JLabel lblDatabasensUrl = new JLabel("Databasens url:");
//		lblDatabasensUrl.setBounds(10, 155, 101, 14);
//		add(lblDatabasensUrl);
//		
//		JLabel lblRootPass = new JLabel("Root pass:");
//		lblRootPass.setBounds(10, 180, 75, 14);
//		add(lblRootPass);
//		
//		textURL = new JTextField();
//		textURL.setText(teraFootMain.getDbConnection().getDATABASE_URL());
//		textURL.setActionCommand("Opdater info");
//		textURL.addActionListener(teraFootMain.getAcListener());
//		textURL.setBounds(110, 152, 246, 20);
//		add(textURL);
//		textURL.setColumns(10);
//		
//		textRoot = new JTextField();
//		textRoot.setText(teraFootMain.getDbConnection().getRootPass());
//		textRoot.setActionCommand("Opdater info");
//		textRoot.addActionListener(teraFootMain.getAcListener());
//		textRoot.setBounds(110, 177, 147, 20);
//		add(textRoot);
//		textRoot.setColumns(10);
//		
//		btnOpdaterInfo = new JButton("Opdater info");
//		btnOpdaterInfo.setActionCommand("Opdater info");
//		btnOpdaterInfo.addActionListener(teraFootMain.getAcListener());
//		btnOpdaterInfo.setBounds(110, 208, 147, 23);
//		add(btnOpdaterInfo);

//		btnOpretDB = new JButton("Opret alle databaser");
//		btnOpretDB.setActionCommand("OpdaterDB");
//		btnOpretDB.addActionListener(teraFootMain.getAcListener());
//		btnOpretDB.setBounds(267, 266, 173, 23);
//		add(btnOpretDB);

	}

	public void refreshComboBox() {
		final ArrayList<String> userNames = teraFootMain.getDbConnection()
				.allUsers();
		final String[] users = userNames.toArray(new String[0]);
		comboBox.setModel(new DefaultComboBoxModel(users));
	}

	public JTextField getTextBruger() {
		return textBruger;
	}

	public JTextField getTextKode() {
		return textKode;
	}

	public JButton getBtnOpret() {
		return btnOpret;
	}

	public JLabel getLblStatus() {
		return lblStatus;
	}

	public JComboBox getComboBox() {
		return comboBox;
	}

	public JButton getBtnSletBruger() {
		return btnSletBruger;
	}
//	public JTextField getTextURL() {
//		return textURL;
//	}
//	public JTextField getTextRoot() {
//		return textRoot;
//	}
//	public JButton getBtnOpdaterInfo() {
//		return btnOpdaterInfo;
//	}
//	public JButton getBtnOpretDB() {
//		return btnOpretDB;
//	}

}
